package jus.aor.mobilagent.hostel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;

import jus.aor.mobilagent.kernel.Agent;
import jus.aor.mobilagent.kernel._Action;

public class LookForHotel extends Agent{

	private static final long serialVersionUID = -4763191657005232135L;

	/**
	  * construction d'un agent de type hello.
	  * @param args aucun argument n'est requis
	  */
	String ville;
	List<Hotel> hotels = new ArrayList<Hotel>(); 
	List<String> numeros = new ArrayList<String>();
	Long duration;
	
	 public LookForHotel(Object... args) {
		 super();
		 ville = (String)args[0];
		 
	 }
	 /**
	 * l'action à entreprendre sur les serveurs visites  
	 */
	public _Action findHotel = new _Action(){
		private static final long serialVersionUID = -9129644307555501553L;

		public void execute(){
			hotels.addAll((ArrayList<Hotel>)serv.getService("Hotels").call(ville));
		}

	};
	
	public _Action findTelephone = new _Action(){
		private static final long serialVersionUID = -9129644307555501553L;

		public void execute(){
			for (int i =0;i<hotels.size();i++){
				numeros.add((String) serv.getService("Telephones").call(hotels.get(i).name));
			}
		}

	};
	
	public _Action start = new _Action(){
		private static final long serialVersionUID = -9129644307555501553L;
		public void execute(){
			duration = new Date().getTime();
			//serv.logger.log(Level.FINE,"Timestamp de depart: "+duration);
		}

	};
	/* (non-Javadoc)
	 * @see jus.aor.mobilagent.kernel.Agent#retour()
	 */
	public _Action retour(){
		return new _Action(){
			private static final long serialVersionUID = -9129644307555501553L;
				
			public void execute(){
				duration = (Long) serv.getService("Duration").call(duration);
				serv.logger.log(Level.FINE,"Temps en millisecondes: "+duration);
			/*	for (int i =0;i<hotels.size();i++){
					System.out.print(hotels.get(i).name+" "+hotels.get(i).localisation+" ");
					System.out.println(numeros.get(i));
				} */
			}

		};

	}
	public String toString() {
		return "create Hello";
	}

}
